package com.xu.tools.exception;


import java.text.MessageFormat;

/**
 * @author xuguan
 * @desc 通用异常类
 */
public class CommonException extends RuntimeException {
    private static final long serialVersionUID = -3318249577791385548L;
    private final Integer code;

    public CommonException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    @Override
    public String getMessage() {
        String message = super.getMessage();
        return MessageFormat.format("code={0}, message={1}", code, message);
    }

    public Integer getCode() {
        return code;
    }

    public static void throwException(Integer code, String msg) {
        throw new CommonException(code, msg);
    }
}
